package com.mriassl.rabbitmq.topic;

import java.io.IOException;

import com.mriassl.rabbitmq.base.AbstractProducer;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

public class LogProducer extends AbstractProducer {
	
	@Override
	protected void doSometing(Connection conn, Channel channel) throws IOException {
		channel.exchangeDeclare(TopicConsts.EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
		// 待发送的消息  
        String[] routingKeys = new String[]{"quick.orange.rabbit",   
                                            "lazy.orange.elephant",   
                                            "quick.orange.fox",   
                                            "lazy.brown.fox",   
                                            "quick.brown.fox",   
                                            "quick.orange.male.rabbit",   
                                            "lazy.orange.male.rabbit"};
		for(String routingkey : routingKeys){
			String message = "From "+routingkey+" routingKey' s message!"; 
			channel.basicPublish(TopicConsts.EXCHANGE_NAME, routingkey, null, message.getBytes());
			System.out.println(" [x] Sent '" + message + "'");
		}
	}
	
	public static void main(String[] args) throws Exception {
		LogProducer plog = new LogProducer();
		plog.publicMsg();
	}
	
}
